#include "menudialog.h"
#include "ui_menudialog.h"

int MenuDialog::GAMEMODE = RobotPk;

MenuDialog::MenuDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MenuDialog)
{
    ui->setupUi(this);
    this->setWindowTitle("五子棋");
    InitStyle();
    ui->label_double->installEventFilter(this);
    ui->label_robotPk->installEventFilter(this);
    ui->label_networkPk->installEventFilter(this);
}

MenuDialog::~MenuDialog()
{
    delete ui;
}

void MenuDialog::InitStyle()
{
    QFile file("../GoBang/LoginStyle.qss");
    if(!file.open(QIODevice::ReadOnly))
        qDebug()<<"LoginStyle.qss open failed!";
    QString style = file.readAll();
    file.close();
    this->setStyleSheet(style);

    QFontDatabase::addApplicationFont(":/new/font/Alimama_DongFangDaKai_Regular.ttf"); //Alimama DongFangDaKai
}

bool MenuDialog::eventFilter(QObject *obj, QEvent *event)
{
    if(obj == ui->label_robotPk)        //人机对弈
    {
        if(event->type() == QEvent::MouseButtonPress)
        {
            QMouseEvent* ev = static_cast<QMouseEvent*>(event);
            if(ev->button()==Qt::LeftButton)
            {
                GAMEMODE = RobotPk;
                QDialog::accept();
                return true;
            }
        }
    }
    else if(obj == ui->label_networkPk){    //网络对战
        if(event->type() == QEvent::MouseButtonPress)
        {
            QMouseEvent* ev = static_cast<QMouseEvent*>(event);
            if(ev->button()==Qt::LeftButton)
            {
                GAMEMODE = NetworkPk;
                QDialog::accept();
                return true;
            }
        }
    }
    else if(obj == ui->label_double){       //本地双人
        if(event->type() == QEvent::MouseButtonPress)
        {
            QMouseEvent* ev = static_cast<QMouseEvent*>(event);
            if(ev->button()==Qt::LeftButton)
            {
                GAMEMODE = DoublePk;
                QDialog::accept();
                return true;
            }
        }
    }
    return false;
}
